package com.jiazhong.shixi.caichanguanli.controller;

import com.jiazhong.shixi.caichanguanli.bean.WorkOrders;
import com.jiazhong.shixi.caichanguanli.mapper.WorkOrdersMapper;
import com.jiazhong.shixi.caichanguanli.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.List;

@CrossOrigin("*")
@RestController
@RequestMapping("/work-orders")
public class WorkOrdersController {
    @Resource
    private WorkOrdersMapper workOrdersMapper;

    @RequestMapping("/add")
    public JsonResult createWorkOrder( WorkOrders order) {
        workOrdersMapper.insert(order);
        JsonResult result = new JsonResult(true, 200, "已报修，待处理", "");
        return result;
    }

    @RequestMapping("/FreshOrder")
    public JsonResult findByFreshOrder() {
        List<WorkOrders> list =workOrdersMapper.findByFreshOrder();
        JsonResult result = new JsonResult(true, 200, list, "");
        return result;
    }

    @RequestMapping("/Fresh")
    public JsonResult findByFresh() {
        List<WorkOrders> list =workOrdersMapper.findByFresh();
        JsonResult result = new JsonResult(true, 200, list, "");
        return result;
    }


    @RequestMapping("/delete")
    public JsonResult deleteWorkOrder(WorkOrders order) {
        workOrdersMapper.deleteById(order);
        JsonResult result = new JsonResult(true, 200, "已处理", "");
        return result;
    }
}
